<hr/>
<div class="row-fluid">
    <div class="span12">
        <button class="btn btn-success" id="btn_save">保存</button>
        <a href="${request.contextPath}/product/infoList" class="btn btn-info" id="btn_back">返回列表</a>
        <div class="widget-box">
            <div class="widget-title"> <span class="icon"> <i class="icon-pencil"></i> </span>
                <h5>商品类型</h5>
            </div>
            <div class="widget-content nopadding">
                <form class="form-horizontal" method="post" action="${request.contextPath}/product/saveCatalog" name="catalog_form" id="catalog_form">
                    <input type="hidden" name="catalogId" value="${catalog.productCatalogId}" />
                    <div class="control-group">
                        <label class="control-label">类型名称：</label>
                        <div class="controls">
                            <input type="text" name="catalogName" value="${catalog.catalogName}">
                        </div>
                    </div>
                    <div class="control-group">
                        <label class="control-label">类型规格：</label>
                        <div class="controls">
                            <#list specList as spec>
                                <label>
                                    <input type="checkbox" name="spec" value="${spec.productSpecId}" <#list catalog.catalogSpecList as catalogSpec><#if catalogSpec.productSpec.productSpecId == spec.productSpecId >checked</#if></#list> /> ${spec.specName}
                                </label>
                            </#list>
                        </div>
                    </div>
                    <div class="control-group">
                        <label class="control-label">是否打折：</label>
                        <div class="controls">
                            <label>
                                <input type="radio" name="discount" value="yes" <#if catalog.discount == "yes">checked</#if> > 打折
                            </label>
                            <label>
                                <input type="radio" name="discount" value="no" <#if catalog.discount == "no">checked</#if>> 不打折
                            </label>
                        </div>
                    </div>
                    <div class="control-group">
                        <label class="control-label">排序号：</label>
                        <div class="controls">
                            <input type="text" name="orderNum" value="${catalog.orderNum}" />
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
<script src="${request.contextPath}/js/jquery-1.12.2.min.js"></script>
<script src="${request.contextPath}/js/jquery.validate.js"></script>
<script src="${request.contextPath}/js/sweetalert.min.js"></script>
<script src="${request.contextPath}/js/select2.full.min.js"></script>
<script type="text/javascript">
    $(function(){

        $("#btn_back").click(function(){
            loadPage($(this).attr("href"));
            return false;
        });

        $("#btn_save").click(function(){
            $("#catalog_form").submit();
        });

        $("#catalog_form").validate({
            submitHandler: function(form){
                $.ajax({
                    url: $(form).attr("action"),
                    type: "post",
                    data: $(form).serialize(),
                    success: function(result){
                        swal({
                            title: "信息提示",
                            text: result.status == "success" ? "恭喜，操作已完成！" : "很遗憾，操作失败了！",
                            type: result.status,
                            animation: "slide-from-top"
                        }, function(){
                            if (result.status == "success"){
                                loadPage("${request.contextPath}/product/infoList");
                            }
                        });
                    }
                });
            },
            rules: {
                specName: {
                    "required": true
                }
            },
            errorClass: "help-inline",
            errorElement: "span",
            highlight:function(element, errorClass, validClass) {
                $(element).parents('.control-group').addClass('error');
            },
            unhighlight: function(element, errorClass, validClass) {
                $(element).parents('.control-group').removeClass('error');
                $(element).parents('.control-group').addClass('success');
            }

        });
    })
</script>